package com.szy.douyou_gateway.web;


import com.szy.douyou_gateway.config.ResultDTO;
import com.szy.douyou_gateway.service.FileUploadService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 文件上传
 * @author sunziyan
 * @date 2022/4/2
 */
@RestController
public class FileUploadController {

    @Resource
    private FileUploadService fileUploadService;


    /**
     * 文件上传到cos返回url地址
     * @param multipartFile
     * @return
     */
    @PostMapping("/getImageUploadUrl")
    public ResultDTO getImageUploadUrl(@RequestParam("image")MultipartFile multipartFile){
        if(multipartFile.isEmpty()){
            return ResultDTO.fail("文件为空");
        }

        return ResultDTO.success(fileUploadService.getImageUploadUrl(multipartFile));

    }





}
